package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "用户信息接口")
@RequestMapping("/admin/system/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询用户信息")
    public Result<PageInfo<SysUser>> findByPage(SysUserDto sysUserDto, @PathVariable Integer pageNum, @PathVariable Integer pageSize){
        PageInfo<SysUser> pageInfo = sysUserService.findByPage(sysUserDto, pageNum, pageSize);

        return Result.OK(pageInfo);
    }

    @PostMapping("/saveSysUser")
    @Operation(summary = "添加用户")
    public Result saveSysUser(@RequestBody SysUser sysUser){
        sysUserService.savaSysUser(sysUser);
        return Result.OK(null);
    }

    @PutMapping("/updateSysUser")
    @Operation(summary = "修改用户信息")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        sysUserService.updateSysUser(sysUser);
        return Result.OK(null);
    }

    @DeleteMapping("/deleteById/{userId}")
    public Result deleteById(@PathVariable Long userId){
        sysUserService.deleteById(userId);
        return Result.OK(null);
    }

}
